package practise.leetcode.q155;

import java.util.Stack;

public class MinStack {

    private Stack<Integer> nums = new Stack<>();
    private int min = Integer.MAX_VALUE;

    public MinStack() {
    }

    public void push(int x) {
        if (min >= x) {
            nums.push(min);
            min = x;
        }
        nums.push(x);
    }

    public void pop() {
        if (nums.pop() == min) {
            min = nums.pop();
        }
    }

    public int top() {
        return nums.peek();
    }

    public int getMin() {
        return min;
    }
}
